<script src="http://staging.tokbox.com/v0.91/js/TB.min.js"></script>
<script type="text/javascript">
	var apiKey = '<?php echo $api_key; ?>';
	var sessionId = '<?php echo $session_id; ?>';
	var token = '<?php echo $token; ?>';           
     
    TB.setLogLevel(TB.DEBUG);    
 
    var session = TB.initSession(sessionId);     
    session.addEventListener('sessionConnected', sessionConnectedHandler);
    session.addEventListener("connectionDestroyed", connectionDestroyedHandler);
    session.addEventListener('streamCreated', streamCreatedHandler);     
    session.connect(apiKey, token);
 
    var publisher;
 
    function sessionConnectedHandler(event) {
      publisher = session.publish('myPublisherDiv');
       
      // Subscribe to streams that were in the session when we connected
      subscribeToStreams(event.streams);
    }

    function connectionDestroyedHandler(event) {
        $('#subscribeContainer').html('<div id="SubscribeDiv"><?php echo $disconnect_message; ?></div>');
    }
     
    function streamCreatedHandler(event) {
      // Subscribe to any new streams that are created
      subscribeToStreams(event.streams);
    }
     
    function subscribeToStreams(streams) {
      for (var i = 0; i < streams.length; i++) {
        // Make sure we don't subscribe to ourself
        if (streams[i].connection.connectionId == session.connection.connectionId) {
          return;
        }
 
        // Subscribe to the stream
        session.subscribe(streams[i], 'SubscribeDiv');
      }
    }
</script>
<center>
	<table width="600">
		<tr height="250">
			<td align="center" valign="middle" width="50%">
				<div id="subscribeContainer" class="center">
					<div id="SubscribeDiv">
						<?php echo $waiting_message; ?>
					</div>
				</div>
			</td>
			<td align="center" valign="middle">
				<div id="publisherContainer" class="center">
					<div id="myPublisherDiv">
						<?php echo $this->lang->line('interview_loadingwebcam'); ?>
					</div>
				</div>
			</td>
		</tr>
	</table>
</center>